<?php

/**
 * Created by PhpStorm.
 * User: Aliaksei Lazerka
 * Date: 10/17/14
 * Time: 9:16 PM
 */
class ActionResolver
{

  /**
   * @var \message\MessageResources
   */
  private $parser;

  /**
   * @var ActionResolver
   */
  private static $resolver;

  const LANG = "eng";


  static function getInstance()
  {
    if (!self::$resolver) {
      self::$resolver = new ActionResolver();
    }
    return self::$resolver;
  }

  function __construct()
  {
    $this->parser = new \message\MessageResources();
    $this->parser->addFile(array("conf/mappings.properties"), self::LANG);
  }
//
//  static function getAction($action)
//  {
//    $resolver = self::getInstance();
//    return $resolver->getParser()->getMessageByKey($action, self::LANG);
//  }

  /**
   * @return \message\MessageResources
   */
  public function getParser()
  {
    return $this->parser;
  }

  /**
   * @param \message\MessageResources $parser
   */
  public function setParser($parser)
  {
    $this->parser = $parser;
  }

  /**
   * @return string
   */
  public static function getActionFromUrl()
  {
    $key = array_keys($_GET);
    $key = $key[0];
    $resolver = self::getInstance();
    if (!$key) {
      return $resolver->getParser()->getMessageByKey("default.mapping", self::LANG);
    }
    return $resolver->getParser()->getMessageByKey($key, self::LANG);
  }

  /**
   * @return string
   */
  public static function getActionNameFromUrl()
  {
    $key = array_keys($_GET);
    $key = $key[0];
    return $key;
  }
}